package com.youchuang.util;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.youchuang.bean.CategoryProduct;

public class CategoryProductUtil {

	public static void sortByCatId(List<CategoryProduct> list) {
		CatIdComparator comparator = new CatIdComparator();
		Collections.sort(list, comparator);
	}

	static class CatIdComparator implements Comparator<CategoryProduct> {

		public CatIdComparator() {
		}

		/**
		 * 如果o1小于o2,返回一个负数;如果o1大于o2，返回一个正数;如果他们相等，则返回0;
		 */
		@Override
		public int compare(CategoryProduct o1, CategoryProduct o2) {
			int result = o1.getCategoryId().compareTo(o2.getCategoryId());
			if (result > 0) {
				return 1;
			} else if (result == 0) {
				return 0;
			} else {
				return -1;
			}

		}

	}

}
